<template>
  <base-breadcrumb :title="titleName">
    <a-card :bordered="false">
      <!-- <title-name title="节点管控信息列表" /> -->
      <!--<div class="table-operator">-->
      <!--<a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>-->
      <!--</div>-->

      <list-table
        ref="table"
        size="default"
        row-key="key"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        show-pagination="auto"
      >
        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <template
          slot="redTipDays"
          slot-scope="text, record, index"
        >
          <span v-if="record.controlLevelName != '三级节点' "> {{ record.redTipDays }}</span>
          <span v-if="record.controlLevelName == '三级节点' "> 无</span>
        </template>
        <template
          slot="yellowTipDays"
          slot-scope="text, record, index"
        >
          <span v-if="record.controlLevelName != '三级节点' ">{{ record.yellowTipDays }}</span>
          <span v-if="record.controlLevelName == '三级节点' "> 无</span>
        </template>

        <span
          slot="action"
          slot-scope="text, record"
        >
          <MoreButton>
            <a
              v-btnPermission="[{code:'seex_pm_012_loo_01',ident:'prma_seex'},{code:'buco_pm_012_loo_01',ident:'prma_buco'}]"
              @click="handleControl(record,'detail')"
            >查看</a>
            <a
              v-btnPermission="[{code:'seex_pm_012_edi_02',ident:'prma_seex'},{code:'buco_pm_012_edi_02',ident:'prma_buco'}]"
              @click="handleControl(record,'update')"
            >编辑</a>
          </MoreButton>
        </span>
      </list-table>

      <!-- <add-type
        ref="createModal"
        :visible="visible"
        :loading="confirmLoading"
        :model="mdl"
        @cancel="handleCancel"
        @ok="handleOk"
      />

      <find-type
        ref="createModal"
        :visible="visibles"
        :loading="confirmLoading"
        :model="mdls"
        @cancel="handleCancels"
      /> -->
      <OperationControl
        :visible.sync="visible"
        :record="mdl"
        :type="type"
        @refresh="$refs.table.refresh(true)"
      />
    </a-card>
  </base-breadcrumb>
</template>

<script>
import moment from 'moment'
import { STable, Ellipsis } from '@/components'
import { getConstructionsList, addConstructions, getCalType } from '@/api/construction'

import addType from './addConstruction'
import findType from './findConstruction'
import OperationControl from './components/OperationControl'
import ARow from 'ant-design-vue/es/grid/Row'

const columns = [
  {
    title: '序号',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '项目重要程度',
    dataIndex: 'importanceName'
  },
  {
    title: '节点等级',
    dataIndex: 'controlLevelName'
  },
  {
    title: '计划开始提示时间(天)',
    dataIndex: 'startTipDays'
  },
  {
    title: '计划结束提示时间(天)',
    dataIndex: 'endTipDays'
  },
  {
    title: '红灯亮灯时间(天)',
    dataIndex: 'redTipDays',
    scopedSlots: { customRender: 'redTipDays' }
  },
  {
    title: '黄灯亮灯时间(天)',
    dataIndex: 'yellowTipDays',
    scopedSlots: { customRender: 'yellowTipDays' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 150,
    scopedSlots: { customRender: 'action' }
  }
]

const statusMap = {
  0: {
    status: 'default',
    text: '关闭'
  },
  1: {
    status: 'processing',
    text: '运行中'
  },
  2: {
    status: 'success',
    text: '已上线'
  },
  3: {
    status: 'error',
    text: '异常'
  }
}

export default {
  name: 'a' + Date.now(),
  components: {
    STable,
    addType,
    findType,
    OperationControl
  },
  data() {
    this.columns = columns
    return {
      titleName: '',
      // create model
      visible: false,
      visibles: false,
      confirmLoading: false,
      mdl: null,
      mdls: null,
      // 操作节点管控类型
      type: '',
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getConstructionsList(requestParameters).then((res) => {
          return res
        })
      },
      selectedRowKeys: [],
      selectedRows: [],
      isEdit: false,
      calType: []
    }
  },
  filters: {
    statusFilter(type) {
      return statusMap[type].text
    },
    statusTypeFilter(type) {
      return statusMap[type].status
    }
  },
  created() {},
  computed: {
    // rowSelection() {
    //   return {
    //     selectedRowKeys: this.selectedRowKeys,
    //     selectedRows: this.selectedRows,   // 当前行所有数据
    //     onChange: this.onSelectChange
    //   }
    // }
  },
  methods: {
    // handleAdd() {
    //   // this.$refs.createModal.form.resetFields(true)
    //   this.confirmLoading = false
    //   this.mdl = null
    //   this.visible = true
    //   this.isEdit = false
    // },
    /**
     * @description: 查看编辑节点
     * @param {object} record 行数据
     * @param {string} type 操作类型
     * @return {void}
     */
    handleControl(record, type) {
      this.visible = true
      this.type = type
      if (record.controlLevelName == '三级节点') {
        record.redTipDays = '无'
        record.yellowTipDays = '无'
      }
      this.mdl = record
    },
    // handleOk() {
    //   let that = this
    //   const form = that.$refs.createModal.form
    //   that.confirmLoading = true
    //   form.validateFields((errors, values) => {
    //     if (!errors) {
    //       if (that.isEdit == true) {
    //         let obj = {}

    //         obj.controlLevelId = that.mdl.controlLevelId
    //         obj.controlLevelName = that.mdl.controlLevelName
    //         obj.endTipDays = values.endTipDays
    //         obj.startTipDays = values.startTipDays
    //         obj.redTipDays = values.redTipDays
    //         obj.yellowTipDays = values.yellowTipDays

    //         if (that.mdl.redTipDays === '无') {
    //           obj.redTipDays = null
    //         }
    //         if (that.mdl.yellowTipDays === '无') {
    //           obj.yellowTipDays = null
    //         }

    //         editConstructions(obj).then((res) => {
    //           if (res.code == 200) {
    //             that.visible = false
    //             that.confirmLoading = false
    //             // 重置表单数据
    //             // form.resetFields()
    //             // 刷新表格
    //             that.$refs.table.refresh(true)
    //             that.$message.success('修改成功！')
    //           } else {
    //             that.$message.error('修改失败！ ')
    //             that.visible = false
    //             // form.resetFields()
    //           }
    //         })
    //       } else {
    //         // 新增

    //         addConstructions(values).then((res) => {
    //           if (res.code == 200) {
    //             that.visible = false
    //             that.confirmLoading = false
    //             // 重置表单数据
    //             // form.resetFields()
    //             // 刷新表格
    //             that.$refs.table.refresh(true)
    //             that.$message.info('新增成功！')
    //           } else {
    //             that.$message.info('新增失败！')
    //             // 重置表单数据
    //             // form.resetFields()
    //             that.visible = false
    //           }
    //         })
    //       }
    //     } else {
    //       that.confirmLoading = false
    //     }
    //   })
    // },
    // handleCancel() {
    //   this.visible = false

    //   const form = this.$refs.createModal.form
    //   // form.resetFields()
    // },
    // handleCancels() {
    //   this.visibles = false
    // },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    }
  }
}
</script>


